<?php
namespace App\Http\Controllers\ApiWx;

use App\DBs\MemberDB;
use App\DBs\OrderDB;
use App\DBs\VideoDB;
use Illuminate\Http\Request;

class MyController extends BaseController
{
    //佣金

    protected $db;
    protected $mem;
    protected $order;
    protected $address;

    public function __construct()
    {
        parent::__construct();
        $this->db = new VideoDB();
        $this->mem = new MemberDB();
        $this->order = new OrderDB();
    }

    /**
     * 统计
     */
    public function getMyIndex(Request $request)
    {
        $wx = $request->post('wx','');
        //已推荐好友N人
        $friends = $this->mem->getFriendIndex($wx);
        //我已下单N次
        $orders = $this->order->getIndexByUser($wx);
        //抽奖机会N次
        $rewards = $this->mem->getRewardsTotal($wx);
        //会员类型
        //我赞过的
        $items = [
        ];
    }

    /**
     * 好友列表
     */
    public function getFriendIndex(Request $request)
    {
        $wx = $request->post('wx','');
        if (!$wx) {
            return $this->toWxJson(-4);
        }
        $resDb = $this->mem->getFriendIndex($wx);
        if ($resDb['code']!=0) {
            return $this->toWxJson(-3);
        }
        $items = $resDb['data'];
        return $this->toWxJson(0,$items);
    }

    /**
     * 点赞列表
     */
    public function getPraiseIndex(Request $request)
    {
        $wx = $request->post('wx','');
        if (!$wx) {
            return $this->toWxJson(-4);
        }
        $resDb = $this->db->getPraiseIndex($wx);
        if ($resDb['code']!=0) {
            return $this->toWxJson(-3);
        }
        $items = $resDb['data'];
        return $this->toWxJson(0,$items);
    }

    /**
     * 活动列表
     */
    public function getActivityIndex(Request $request)
    {
        $wx = $request->post('wx','');
        if (!$wx) {
            return $this->toWxJson(-4);
        }
        $resDb = $this->mem->getActivityIndex();
        if ($resDb['code']!=0) {
            return $this->toWxJson(-3);
        }
        $items = $resDb['data'];
        return $this->toWxJson(0,$items);
    }
}